<template>
  <a-form :form="form">
    <a-col :span="9" :offset="2">
      <a-form-item label="证书名称">
        <a-input
          v-decorator="[
            'name',
            {
              rules: [{ required: true, message: '请输入' }],
              initialValue: item.name
            }
          ]"
        />
      </a-form-item>
    </a-col>
    <a-col :span="9" :offset="2">
      <a-form-item label="证书编号">
        <a-input v-decorator="['number', { initialValue: item.number }]" />
      </a-form-item>
    </a-col>
    <a-col :span="9" :offset="2">
      <a-form-item label="证书起始日期">
        <a-date-picker type="date" placeholder="选择日期" v-decorator="['startTime', { initialValue: getMoment(item.startTime) }]" />
      </a-form-item>
    </a-col>
    <a-col :span="9" :offset="2">
      <a-form-item label="证书失效日期">
        <a-date-picker type="date" placeholder="选择日期" v-decorator="['endTime', { initialValue: getMoment(item.endTime) }]" />
      </a-form-item>
    </a-col>
    <a-col :span="9" :offset="2">
      <a-form-item label="证书备注">
        <a-input type="textarea" v-decorator="['remark', { initialValue: item.remark }]" />
      </a-form-item>
    </a-col>
    <a-col :offset="2" :span="22">
      <div class="basicInfo-button-group">
        <a-button type="primary" @click="editEmpCertificate">确认</a-button>
      </div>
    </a-col>
  </a-form>
</template>

<script>
import { editEmpCertificate } from "@/api/staff/certificate";

export default {
  name: "CertForm",
  data() {
    return {
      form: this.$form.createForm(this)
    };
  },
  props: { item: {} },
  methods: {
    getMoment(date) {
      return date ? this.moment(date) : null;
    },
    alertResultMessage(result) {
      let type = "success";
      if (result.code !== 200) {
        type = "error";
      }

      this.$message({
        message: result.msg,
        type: type
      });
    },
    editEmpCertificate() {
      this.form.validateFields((err, values) => {
        if (!err) {
          values.id = this.item.id;
          editEmpCertificate(values).then(res => {
            this.alertResultMessage(res);
          });
        }
      });
    }
  }
};
</script>

<style scoped></style>
